package com.huaxin.hxmoduleworkorder.dto.request;

import com.huaxin.hxmoduleworkorder.common.annotation.validation.ValidCustomerType;
import com.huaxin.hxmoduleworkorder.common.annotation.validation.ValidMaintenanceOrderPriority;
import com.huaxin.hxmoduleworkorder.common.annotation.validation.ValidMaintenanceOrderSourceType;
import com.huaxin.hxmoduleworkorder.dto.request.base.baseMaintenanceOrderOperationReqDTO;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * 更新维保工单请求 DTO（包含 ID）
 * <p>
 * 对应实体类：MaintenanceOrder
 * 用于接收前端提交的维保工单更新数据，包含主键 ID。
 * 适用于需要自包含请求体的更新场景。
 * 使用 jakarta.validation 进行参数校验。
 * </p>
 *
 * @author [你的名字或团队]
 * @since 2025-09-02
 */
@Data
@SuperBuilder
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
public class MaintenanceOrderUpdateReqDTO extends baseMaintenanceOrderOperationReqDTO {
    @Schema(description = "工单标题", example = "客户报修：配电箱跳闸")
    @NotBlank(message = "工单标题不能为空")
    @Size(max = 100, message = "工单标题长度不能超过100个字符")
    private String title;

    @Schema(description = "问题描述", example = "客户反映家中频繁跳闸")
    @Size(max = 1000, message = "问题描述长度不能超过1000个字符")
    private String description;

    @Schema(description = "优先级：low（低）/medium（中）/high（高）", example = "high")
    @NotNull
    @ValidMaintenanceOrderPriority
    private String priority;

    @Schema(description = "来源：customer（客户报修）/electrician（电工上报）/admin（后台创建）/inspection（巡查发现）", example = "customer")
    @NotBlank(message = "来源类型不能为空")
    @Size(max = 30, message = "来源类型长度不能超过30个字符")
    @ValidMaintenanceOrderSourceType
    private String sourceType;

    @Schema(description = "来源ID（如来自巡查工单或巡查项ID）", example = "ins_order_001")
    @Size(max = 50, message = "来源ID长度不能超过50个字符")
    private String sourceId;

    @Schema(description = "客户类型，允许值：residential（住宅）/industrial（工业）/commercial（商业）", example = "residential")
    @NotNull
    @ValidCustomerType
    private String customerType;

    @Schema(description = "客户ID", example = "c1001")
    @NotBlank(message = "客户ID不能为空")
    @Size(max = 50, message = "客户ID长度不能超过50个字符")
    private String customerId;

    @Schema(description = "客户名称", example = "张三")
    @NotBlank(message = "客户名称不能为空")
    @Size(max = 50, message = "客户名称长度不能超过50个字符")
    private String customerName;

    @Schema(description = "关联设备ID（可选）", example = "eqp_001")
    @Size(max = 50, message = "设备ID长度不能超过50个字符")
    private String equipmentId;

    @Schema(description = "客户联系电话", example = "13800138000")
    @NotBlank(message = "联系电话不能为空")
    @Pattern(regexp = "^1[3-9]\\d{9}$", message = "联系电话格式不正确")
    private String contactPhone;

    @Schema(description = "客户期望上门时间（时间段，开始和结束）", example = "[\"2025-09-02 09:00\",\"2025-09-02 12:00\"]")
    private List<String> preferredTime;

    @Schema(description = "客户地址", example = "北京市朝阳区XX路XX号")
    @NotBlank(message = "客户地址不能为空")
    @Size(max = 200, message = "客户地址长度不能超过200个字符")
    private String address;

    @Schema(description = "客户地址经度", example = "116.397128")
    @NotBlank(message = "客户地址经度不能为空")
    private String addressLongitude;

    @Schema(description = "客户地址纬度", example = "39.915119")
    @NotBlank(message = "客户地址纬度不能为空")
    private String addressLatitude;
}